{if isset($conversations)}
<p>Aby oznaczyć wiadomość jako przeczytaną, kliknij na nią</p>

<style type="text/css">
    .seller{
        margin: 5px;
        background-color: #ccffcc
            margin-left: 10px;
    }
    .customer{
        margin: 5px;
        background-color: #ffffcc;
        margin-left: 100px;
    }
    .newMessage {
        font-weight: bold;
    }
    .newMessage::before{
        content: "nowa wiadomość:";
        display: block;
        border-width: 2px;
        border-color: red;
        border-radius: 3px;
        border-style: solid;
    }
    .messages {
        height: 350px;
        overflow: auto;
    }
</style>
<div class="list-group" id="Chat">
    <div id="sound"></div>
    {foreach $conversation in $conversations}
    <div class="panel panel-info" id="Chat">
        <div class="panel-heading link convTitle" style="cursor: pointer">
            <table class="table" style="margin-bottom:0px">
                <tbody>
                    <tr>
                        <td class="col-xs-4" style="color: black">
                            <strong><u><i>
                            Użytkownik<br/>{echo $conversation->CustomerID->PersonID->Name} {echo $conversation->CustomerID->PersonID->Surname} ({echo $conversation->CustomerID->PersonID->Email})
                            </i></u></strong>
                        </td>
                        <td class="col-xs-4">
                            Data rozpoczęcia:<br/>{echo $conversation->AdditionDate} 
                        </td>
                        <td>
                            Temat rozmowy:<br/> {echo $conversation->Topic}
                        </td>
                    </tr>
                </tbody>
            </table>
<!--            <strong><u><i><span style="color: black" class="col-xs-4"></span></i></u></strong>
            <span  class="col-xs-4">Data rozpoczęcia:<br/>{echo $conversation->AdditionDate} </span>     -->
             
            {if $unreadConv[$conversation->ConversationID]>0}
            <div id="newMessage{echo $conversation->ConversationID}" class="badge">nowe wiadomości: <span class="count">{echo $unreadConv[$conversation->ConversationID]}</span></div>
            {/if}
        </div>
        <div id="AllConversation{echo $conversation->ConversationID}" class="panel-body" style="display: none">
            <input type="hidden" value="{echo $conversation->ConversationID}">
            <div class="messages">
                {foreach $message in $messages[$conversation->ConversationID]}
                {if $message->SendByCustomer==1}
                {if $message->Seen==0}
                <div class="customer newMessage">
                    <input type="hidden" value="{echo $message->AnswerID}">
                    {/if}
                    {else}
                    <div class="customer">
                        {/else}
                        {echo $message->AdditionDate}<br/>
                        {echo $message->Content}
                    </div>
                    {/if}
                    {else}
                    <div class="seller">
                        {echo $message->AdditionDate}<br/>
                        {echo $message->Content}
                    </div>
                    {/if}
                    {/else}         
                    {/foreach}
                </div>
                <div id="conversation{echo $conversation->ConversationID}" class="col-xs-8"> </div>
                <button type="button" class="btn btn-default sendMessage col-xs-5">Wyślij wiadomość</button>
            </div>
        </div>
    {/foreach} 
</div>
{/if}
<script src="/js/jquery.timer.js" type="text/javascript"></script>
<script src="/js/jquery.playSound.js" type="text/javascript"></script>
<script src="/js/ChatSeller.js?{echo time()}" type="text/javascript"></script>

<script type="text/javascript">
    var ids = [];
    {if isset($conversations)}
    {foreach $conversation in $conversations}
    ids[{echo $conversation_i}] = {echo $conversation -> ConversationID};
    {/foreach}
    {/if}
            var id = {echo $maxID};
            var conversationsCount = {echo $coversationsCount};
    $(document).ready(function () {
        chat(id, ids);
        initMessages(ids);
        sendMessage();
    });
</script>